package com.eightbears.beboy.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.util.SPUtil;
import com.eightbears.greendao.District;

public class FindDistrictSortAdapter extends BaseQuickAdapter<District, BaseViewHolder> {

    private TextView classifyName;
    private ImageView selImg;
    private District mDistrict;

    public FindDistrictSortAdapter() {
        super(R.layout.item_find_location, null);
        mDistrict = SPUtil.getFindDistrictClass();
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, District district) {
        baseViewHolder.setText(R.id.tv_item_name, district.getName())
                .addOnClickListener(R.id.rl_item);
        classifyName = baseViewHolder.getView(R.id.tv_item_name);
        selImg = baseViewHolder.getView(R.id.iv_sel_icon);
        RelativeLayout rl_item = baseViewHolder.getView(R.id.rl_item);
        replaceView();
        if (null != mDistrict && district.getId().equals(mDistrict.getId())) {
            classifyName.setTextColor(mContext.getResources().getColor(R.color.text_select_color));
            selImg.setVisibility(View.VISIBLE);
        }
    }

    public void replaceView() {
        selImg.setVisibility(View.INVISIBLE);
        classifyName.setTextColor(mContext.getResources().getColor(R.color.text_main_color));
    }

    public void selDistrict(District district){
        this.mDistrict = district;
        notifyDataSetChanged();
    }
}
